<!DOCTYPE html>
<html>
<head>
    <title>E8NET</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />

    <include file="./App/Admin/View/Include/css.html" />
    <link href="__PUBLIC__/Admin/css/lib/select2.css" type="text/css" rel="stylesheet" />
    <link rel="stylesheet" href="__PUBLIC__/Admin/css/compiled/form-showcase.css" type="text/css" media="screen" />
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body>

<include file="./App/Admin/View/Include/navbar.html" />
<include file="./App/Admin/View/Include/menu.html" />

<!-- main container -->
<div class="content">


    <div role="breadcrumb">
        <ol class="breadcrumb">
            <li><a href="{:U('Depart/index')}">学院管理</a> / </li>
            <li class="active">修改班级</li>
        </ol>
    </div>

    <div class="container-fluid">

        <div id="pad-wrapper" class="form-page">
            <div class="row-fluid form-wrapper">
                <!-- left column -->
                <div class="span6 column offset3">
                    <form id="sadmin-form" />
                    <input type="hidden" value="{$D.id}" name = "id" id = "bj_id">
                    <div class="field-box">
                        <label>二级学院名称:</label>
                        <select style="width:250px" class="select2" id="xy_id"  placeholder="请选择学院名称" onchange="xyChange();">
                            <foreach name = "XyList" item ="depart_xy">
                                <if condition="$depart_xy['id'] eq $Zy['f_id']" >
                                    <option value="{$depart_xy.id}" selected/>{$depart_xy.name}
                                <elseif condition="$depart_xy['id'] neq $Zy['f_id']"/>
                                    <option value="{$depart_xy.id}" />{$depart_xy.name}
                                </if>
                            </foreach>
                        </select>
                    </div>

                    <div class="field-box" id="mojor_select">
                        <label>专业名称:</label>
                        <select style="width:250px" class="select2"  id = "zySelector">
                            <foreach name = "ZyList" item ="depart_zy">
                                <if condition="$depart_zy['id'] eq $Zy['id']" >
                                    <option value="{$depart_zy.id}" selected/>{$depart_zy.name}
                                    <elseif condition="$depart_zy['id'] neq $Zy['id']"/>
                                    <option value="{$depart_zy.id}" />{$depart_zy.name}
                                </if>
                            </foreach>

                        </select>
                    </div>

                    <div class="field-box">
                        <label>班级名称</label>
                        <input class="span8 inline-input" id = "bj_name" name="name" placeholder="请输入班级名称" type="text" value="{$D.name}"/>
                        <br>
                        <span id="msg" style="display: none; color:darkred">
                            <i class="icon-remove-sign"></i>
                            <small></small>
                        </span>
                    </div>


                    <div class="span6 field-box actions" style="padding-left:360px;">

                        <a href="javascript:edit();" class="btn-flat default">
                            提交表单
                        </a>
                        <a href="{:U('index')}" class="btn-flat gray">
                            放弃提交
                        </a>
                    </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>
<!-- end main container -->

<include file="./App/Admin/View/Include/js.html" />
<script src="__PUBLIC__/Admin/js/jquery-latest.js"></script>
<script src="__PUBLIC__/Admin/js/bootstrap.min.js"></script>
<script src="__PUBLIC__/Admin/js/jquery.uniform.min.js"></script>
<script src="__PUBLIC__/Admin/js/select2.min.js"></script>



<script type="text/javascript">
    $(function () {

        $(".select2").select2({
            placeholder: "请选择一个选项"
        });
    });

    function xyChange() {

        var x_id = $('#xy_id').val();

        $("#mojor_select>div>a>span").html("");
        var zySelector =  $('#zySelector');
        zySelector.html('');
        $.ajax({
            url:"{:U('Depart/getZY')}",
            data:{'x_id':x_id},
            type: "GET",
            dataType:"json",
            success: function(res){
               if(res.status ==  1){

                    for(var i=0;i<res.data.length;i++) {
                        zySelector.append($('<option value="'+res.data[i].id+'">' + res.data[i].name + '</option>'));
                    }
                }else{
                    console.log(res.msg);
                }
            }
        });
    }



    function edit() {
        var x_id = $('#xy_id').val();
        var z_id = $('#zySelector').val();
        var b_id = $('#bj_id').val();
        var bj_name = $('#bj_name').val();
        if ( x_id == "" || z_id == "" || bj_name ==""){
            $('#msg >small').html('二级学院或者专业名称或者班级不能为空!');
            $('#msg').show();
            return;
        }
        $.post('__APP__/Depart/edit_bj',{x_id:x_id,z_id:z_id,b_id:b_id,bj_name:bj_name}, function (result) {
            var obj = eval('('+result+')');
            if (obj.result == "RESULT_OK"){
                window.location.href = obj.data;
            }else{
                $('#msg > small').html(obj.msg);
                $('#msg').show();
            }

        });

    }
</script>


</body>
</html>